package com.whuan.stream.controller;

import com.whuan.stream.config.MqConfig;
import com.whuan.stream.domin.Whuan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class SendMQContorller {

    @Autowired
    private Processor processor;

    @Autowired
    private MqConfig mqConfig;

    @GetMapping("/send")
    public void send(@RequestParam String message){
        Whuan whuan = new Whuan();
        whuan.setId(1);
        whuan.setMessage(message);
        log.info("whuan={}",whuan);
        processor.output().send(MessageBuilder.withPayload(whuan).build());
    }
    @GetMapping("/send1")
    public void send1(@RequestParam String message){
        Whuan whuan = new Whuan();
        whuan.setId(1);
        whuan.setMessage(message);
        log.info("whuan1={}",whuan);
        mqConfig.output().send(MessageBuilder.withPayload(whuan).build());
    }
}
